class Solution {
public:
    bool isLetter(char ch) { return isalpha(ch) || isdigit(ch); }
    bool isPalindrome(string s) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= 'A' && s[i] <= 'Z') {
                s[i] += 32;
            }
        }
        int begin = 0;
        int end = s.size() - 1;
        while (begin < end) {
            while (begin < end && !isLetter(s[begin])) {
                ++begin;
            }
            while (begin < end && !isLetter(s[end])) {
                --end;
            }
            if (s[begin] != s[end]) {
                return false;
            }
            else
            {
                ++begin;
                --end;
            }
        }
        return true;
    }
};
